/* 
 * Copyright (c) 2013 TianYu Technologies, Inc. All rights reserved.   
 * 
 * This software is the confidential and proprietary information of   
 * TianYu Technologies. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with TianYu Technologies.   
 *   
 */
package com.code.pd.proxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * FIXME 类注释信息(此标记自动生成,注释填写完成后请删除)
 * 
 * <pre>
 * 
 * [调用关系:
 * 实现接口及父类:
 * 子类:
 * 内部类列表:
 * ]
 * </pre>
 * 
 * @author 李鹏
 * @since 1.0
 * @version 2013-8-22 李鹏
 */
public class MyCglibProxy implements MethodInterceptor {

	/**
	 * 
	 * @see net.sf.cglib.proxy.MethodInterceptor#intercept(java.lang.Object,
	 *      java.lang.reflect.Method, java.lang.Object[], net.sf.cglib.proxy.MethodProxy)
	 */
	public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3)
			throws Throwable {
		Object result = null;
		System.out.println("MyCglibProxy方法开始前");
		result = arg3.invokeSuper(arg0, arg2);
		System.out.println("MyCglibProxy方法开始后");
		return result;
	}

	/**
	 * FIXME 方法注释信息(此标记自动完成,注释填写完成后请删除)
	 * 
	 * <pre>
	 * 
	 * </pre>
	 * 
	 * @Date 2013-8-22
	 * @author 李鹏
	 */
	public ItemsAppservice getProxyInstance(Object target) {
		Enhancer en = new Enhancer();
		// 进行代理
		en.setSuperclass(target.getClass());
		en.setCallback(this);
		// 生成代理实例
		return (ItemsAppservice) en.create();
	}

}
